<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>flat 与 flatMap</title>
</head>

<body>
  <script>
    /* // flat
    // 将多维数组转化为低维数组（默认降维）
    const arr = [1, 2, 3, 4, [5, 6, [7, 8]]];
    console.log(arr.flat()); // [1, 2, 3, 4, 5, 6, [7, 8]]

    // 参数为深度
    console.log(arr.flat(2)); // [1, 2, 3, 4, 5, 6, 7, 8] */

    // flatMap
    const arr = [1, 2, 3, 4];
    const result = arr.map(item => [item * 10])
    console.log(result); // [[10], [20], [30], [40]]

    const result2 = arr.flatMap(item => [item * 10])
    console.log(result2); // [10, 20, 30, 40]
  </script>
</body>

</html>